﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;

namespace command
{
    // 假设HttpClientUtils是一个自定义的工具类，你需要根据实际情况进行调整
    public static class HttpClientUtils
    {
        public static HttpClient Client { get; set; }

        public static HttpClient Init()
        {
            return new HttpClient();
        }

        public static string DoJsonPost(object content, string url, Dictionary<string, string> headers)
        {

            HttpClient client = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Post, url)
            {
                Content = new StringContent(JsonConvert.SerializeObject(content), Encoding.UTF8, "application/json")
            };

            foreach (var header in headers)
            {
                request.Headers.TryAddWithoutValidation(header.Key, header.Value);
            }

            HttpResponseMessage response = client.SendAsync(request).Result; // 注意：在实际应用中，应避免使用.Result强制同步，这里仅为示例
            return response.Content.ReadAsStringAsync().Result; // 同上，应避免使用.Result
        }
    }
}